<?php

namespace App\Models;

use Encore\Admin\Auth\Database\Administrator;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Show;

class AdminUser extends Administrator
{
    protected $fillable = ['username', 'password', 'name', 'avatar', 'mobile', 'role_type', 'enabled'];

    //所属院系
    public function department()
    {
        return $this->belongsTo(Department::class);
    }

    public static function userOptions()
    {
        $lists = self::query()->where('id', '>', 1)->get();
        $data = [];
        foreach ($lists as $list) {
            $eno = $list->eno ? ('-' . $list->eno) : '';
            $data[$list->id] = $list->name . '-' . $list->username . $eno;
        }
        return $data;
    }

    public function tabShow()
    {
        return Admin::show($this, function (Show $show) {
            $show->panel()->view('show.tab-panel');
            $show->field('eno', __('工号'));
            $show->field('department.name', __('部门'));
            $show->field('name', __('姓名'));
            $show->field('mobile', __('电话'));
            $show->field('email', __('邮箱'));
        });
    }
}
